import socket
import threading
from base import deal
from collections import deque
q = deque([],100)

def get_server_sock(port):
    s1 = socket.socket()
    s1.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    add = ('0.0.0.0',port)
    s1.bind(add)
    s1.listen(1)
    return s1


s1 = get_server_sock(16788)


while True:
    try:
        a,b = s1.accept()
        while True:
            s2 = get_server_sock(16789)
            a2,b = s2.accept()
            s2.close()
            ss = a2.recv(6)
            if ss!=b'1x34x6':
                continue
            break
            
        t = threading.Thread(target=deal,args=(a,a2))
        t.setDaemon(True)
        t.start()
        q.append(t)
       
    except:
        pass

  


